package com.hbsc.service;

import com.hbsc.domain.RegisterPo;
import com.hbsc.domain.RegisterVo;
import com.hbsc.mapper.RegisterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by fanliu on 2017-12-23.
 */
@Component
@Transactional
public class RegisterService {

    @Autowired
    private RegisterMapper registerMapper;

    /**
     * 新增
     * @param po
     */
    public void saveRegisterInfo(RegisterPo po){
        Long count = registerMapper.queryRegisterInfoCount(po.getOpenid());
        if(count != null && count > 0){//存在报名信息
//            registerMapper.updateRegisterInfo(po.getOpenid());
            registerMapper.deleteRegisterInfo(po.getOpenid());
            registerMapper.saveRegisterInfo(po);
        }else{
            registerMapper.saveRegisterInfo(po);
        }
    }

    /**
     * 根据openid查询信息
     * @param openid
     * @return
     */
    public RegisterVo queryRegisterInfo(String openid){return registerMapper.queryRegisterInfo(openid);}
    public Long queryRegisterInfoCount(String openid){return registerMapper.queryRegisterInfoCount(openid);}

    /**
     * 查询所有报名信息
     * @return
     */
    public List<RegisterVo> queryRegisterList(){return registerMapper.queryRegisterList();}
}
